

#第一种方法超级慢，跑几分钟
# 839542176答案
# def judge(x):
#     s = []
#     for i in str(x):
#         if i not in s and i != '0':
#             s.append(i)
#         else:
#             return False
#     return True
#
#
# def g(x, y, z):
#     if not set(str(x)) & set(str(y)):
#         if judge(z) and len(set(str(z))) == 9:
#             return True
#     return False
#
#
#
# for i in range(999890001, 123456789, -1):
#     if judge(i):
#         for j in range(1, int(i ** 0.5) + 1):
#             if i % j == 0:
#                 if judge(j) and judge(i // j) and g(j, i // j, i):
#                     print(i, j, i // j)
#




#
#
# def has_unique_digits(n):
#     s = set()
#     for digit in str(n):
#         if digit in s or digit == '0':
#             return False
#         s.add(digit)
#     return True
#
def is_coprime(a, b):
    return not set(str(a)) & set(str(b))
#
# def find_largest_product():
#     for i in range(999890001, -1, -1):
#         if has_unique_digits(i):
#             sqrt_i = int(i**0.5)
#             for j in range(1, sqrt_i + 1):
#                 if i % j == 0:
#                     pair1, pair2 = j, i // j
#                     if has_unique_digits(pair1) and has_unique_digits(pair2) and is_coprime(pair1, pair2):
#                         print(i, pair1, pair2)
#                         return
#
# find_largest_product()



def has_unique_digits(n):
    digits = set()
    for digit in str(n):
        if digit in digits or digit == '0':
            return False
        digits.add(digit)
    return True

def find_largest_product():
    for i in range(987654321, 123456789, -1):
        if has_unique_digits(i):
            sqrt_i = int(i**0.5)
            for j in range(1, sqrt_i + 1):
                if i % j == 0:
                    pair1, pair2 = j, i // j
                    if has_unique_digits(pair1) and has_unique_digits(pair2) and is_coprime(pair1, pair2):
                        # 如果满足条件，直接输出并返回
                        print(i, pair1, pair2)
                        return

find_largest_product()
